package OrdersSystem;

import static org.junit.Assert.*;

import org.junit.Test;

import DBSystem.DataBase;

public class OrdersCommTest {
	
	private static DataBase db = new DataBase();
	private static OrdersComm testComm = new OrdersComm();

	@Test
	public void testSendAlert() {
		
		testComm.sendAlert(1);
		
		ContactDetails contact = new ContactDetails("Marchmont", "1F1", "Edinburgh", "EH9 1BM",
				"0798993454", "customer1@sms.ed.ac.uk");
		Customer customer = new Customer(111, "Eddie", "Murphy", contact, 0);
		db.storeUser(customer);
		UserAlert testAlertInDB = new UserAlert(1,"This message should be delivered normaly", 111);
		db.storeUserAlert(testAlertInDB);
		// Integration Test Case #11  Existing Alert, existing user in the Database
		System.out.println("Integration Test Case #11: Existing Alert, existing user in the Database.");
		String testResult = testComm.sendAlert(1);
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true,testResult.contains("The alert has the"));
		
		// Integration Test Case #12 Existing Alert, non existing user in the database
		System.out.println("Integration Test Case #12: Existing Alert, non existing user in the database.");
		testAlertInDB = new UserAlert(2, "The receiver of this user does not exist", 130);
		db.storeUserAlert(testAlertInDB);
		testResult = testComm.sendAlert(2);
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("no user registered"));
		
		//Test Case #13 non existing alert in the database
		System.out.println("Integration Test Case #13: Non existing alert in the database.");
		testResult = testComm.sendAlert(3);
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("no alert"));
		
	}

}
